export const getMinutes = function (startDateStr, endDateStr, isBusiness) {
  // isBusiness = "S"
  let startDate = new Date(startDateStr.replace(/-/g, '/') + ':00');
  let endDate = new Date(endDateStr.replace(/-/g, '/') + ':00');

  let startOfWork = isBusiness === 'S' ? 9.5 : 9;//上班时间点
  let offWorkTime = isBusiness === 'S' ? 17.17 : 18;//下班时间点
  let morningOffTime = 12.5;
  let afternoonOnTime = 13.5;
  let workHours = (offWorkTime - startOfWork - (afternoonOnTime - morningOffTime));

  // 时间戳
  let startTimeStamp = startDate.getTime();
  let endTimeStamp = endDate.getTime();
  // 开始日期、结束日期字符串（yyyy-MM-dd）
  let startDateYYYYMMDD = startDateStr.split(' ')[0];
  let endDateYYYYMMDD = endDateStr.split(' ')[0];
  // 开始小时、结束小时
  let startHour = startDate.getHours();
  let endHour = endDate.getHours();
  // 开始分钟、结束分钟
  let startMin = startDate.getMinutes();
  let endMin = endDate.getMinutes();
  //上午工作时长
  let morningWorkHours = (morningOffTime - startOfWork);
  //下午工作时长
  let afternoonWorkHours = (offWorkTime - afternoonOnTime);
  
  if (startDateYYYYMMDD === endDateYYYYMMDD) {// 只请了一天假
    let workTime = 0;
    let workMinute = 0;

    let startPoint = startHour + startMin/60
    let endPoint = endHour + endMin/60
    // console.log(startPoint,endPoint)

    if(startPoint < startOfWork){
      startPoint = startOfWork;
    }
    if(endPoint > offWorkTime){
      endPoint = offWorkTime
    }
    // 上午请假
    if(startPoint <= morningOffTime && endPoint <= morningOffTime){
      workTime += endPoint - startPoint;
    }
    if(startPoint <= morningOffTime && endPoint > morningOffTime && endPoint <= afternoonOnTime){
      workTime += morningOffTime - startPoint;
    }
    // 上午下午都请
    if(startPoint <= morningOffTime && endPoint > afternoonOnTime){
      workTime += endPoint - startPoint - (afternoonOnTime - morningOffTime)
    }
    if(startPoint > morningOffTime && startPoint <= afternoonOnTime && endPoint >= afternoonOnTime){
      workTime += endPoint - afternoonOnTime;
    }
    // 下午请假
    if(startPoint > afternoonOnTime && endPoint > afternoonOnTime){
      workTime += endPoint - startPoint;
    }
    if(workTime < 0){
      workTime = 0;
    }
    workMinute = workTime*60
    return workMinute;
  
  } else {
    // 多天请假
    
    let computedHours = 0;
    let startMinDouble = startMin / 60;
    let startHoursMin = startHour + startMinDouble;
    let endMinDouble = endMin / 60;
    let endHoursMin = endHour + endMinDouble;
    // 如果用户输入的上班时间点小于上班时间点就赋值为上班时间点
    if(startHoursMin < startOfWork){
      startHoursMin = startOfWork;
    }
    if(startHoursMin > offWorkTime){
      startHoursMin = offWorkTime;
    }
    // 如果用户输入的结束时间点大于下班时间点就赋值为下班时间点
    if(endHoursMin > offWorkTime){
      endHoursMin = offWorkTime;
    }
    // 如果用户输入的结束时间小于上班时间点就赋值为上班时间点
    if(endHoursMin < startOfWork){
      endHoursMin = startOfWork;
    }
    // let differenceDays = (endDate - startDate) / 86400000;
    let differenceDays = (endTimeStamp - startTimeStamp) / 86400000;
    // console.log(startHoursMin);
    // 计算请假开始日期
    if (startHoursMin <= 12.5) {
      // 上午开始请假
      computedHours += 12.5 - startHoursMin + afternoonWorkHours;
    } else if (startHoursMin >= 13.5) {
      // 下午开始请假
      computedHours += afternoonWorkHours - (startHoursMin - 13.5);
    }
    // 计算请假结束日期
    if (endHoursMin >= 13.5) {
      // 下午结束请假
      computedHours += endHoursMin - 13.5 + morningWorkHours;
    } else if (endHoursMin <= 12.5) {
      // 上午结束请假
      computedHours += endHoursMin - startOfWork;
    } else if (endHoursMin < 13.5 && endHoursMin > 12.5) {
      computedHours += 12.5 - startOfWork;
    }
    // console.log(differenceDays)
    if(endHoursMin < startHoursMin){
      if (differenceDays >= 1) {
        computedHours += (Math.floor(differenceDays)) * workHours;
      }else {
        computedHours += Math.floor(differenceDays) * workHours;
      }
    }else{
      if (differenceDays >= 1) {
        computedHours += (Math.floor(differenceDays) - 1) * workHours;
      }else {
        computedHours += Math.floor(differenceDays) * workHours;
      }
    }
    // console.log(computedHours)
    return computedHours * 60;
  }
};
